/*
 *@(#)CodebushUtilSupport.java 1.0 Mar 19, 2008
 *Copyright Fution Bai
 *
 */
package codebush.service.support;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 
 * @author Fution Bai
 * @since 1.0
 */
public class CodebushUtilSupport {
	
	public String compressedMyPicturePath;
	
	/**
	 * store the compressed user uploaded picture in the filesystem
	 * @param fromFile
	 * @param userId
	 */
	public void storeCompressedMyPictureInFileSystem(File fromFile, int userId) {
		try {
			File toFile = new File(this.getCompressedMyPicturePath() + userId + ".jpg");
			BufferedInputStream bin = new BufferedInputStream(new FileInputStream(fromFile));
			BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(toFile));
			int c;
			while ((c = bin.read()) != -1) {
				bout.write(c);
			}
			bin.close();
			bout.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public String getCompressedMyPicturePath() {
		return compressedMyPicturePath;
	}

	public void setCompressedMyPicturePath(String compressedMyPicturePath) {
		this.compressedMyPicturePath = compressedMyPicturePath;
	}

}
